import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.ToString;

import java.util.HashMap;
import java.util.Map;

public class App {
    public static void main(String[] args) throws JsonProcessingException {
        //1.创建一个json对象
        ObjectMapper objectMapper=new ObjectMapper();
//        //2.1将对象转换成json字符串
//        Student student=new Student();
//        student.setId(1);
//        student.setName("zhangsan");
//        student.setPassword("123");
//        String result=objectMapper.writeValueAsString(student);
//        System.out.println(result);
        //------------2.2将json字符串转换为对象---
        String jsonStr="{\"id\":1,\"name\":\"zhangsan\",\"password\":\"123\"}";
   //     Student zhangsan=objectMapper.readValue(jsonStr,Student.class);
        HashMap<String,Object> map=objectMapper.readValue(jsonStr,HashMap.class);
        System.out.println(map);
        for(Map.Entry<String,Object> item :map.entrySet()){
            System.out.println(item.getKey()+":"+item.getValue());
        }
    }
@Data
static class Student{
        private int id;
        private String  name;
        private  String password;
    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}
}
